#define _CRT_SECURE_NO_WARNINGS   1
#include"Queue.h"


void QueueInit(Queue* q)
{
	q->fear = NULL;
	q->front = NULL;
	q->size = 0;

}
void QDestroy(Queue* q)
{
	assert(q);
	QNode* cur = q->front;
	while (cur)
	{
		QNode* del = cur;
		cur = cur->next;
		free(del);
	}
}

void QNodePush(Queue* q,QNodeType x)
{
	assert(q);
	QNode* NewNode = (QNode*)malloc(sizeof(QNode));
	NewNode->val = x;
	NewNode->next = NULL;
	
	if (q->fear == NULL)
	{
		q->front = NewNode;
		q->fear = NewNode;
	}
	else
		q->fear->next = NewNode;
	q->size++;

}
void QNodePop(Queue* q)
{
	assert(q);
	assert(q->fear);
	QNode* del = q->front;
	q->front = q->front->next;
	free(del);
	q->size--;

}

int QNodeSize(Queue* q)
{
	return q->size;
}

QNodeType QNodeFear(Queue* q) {

	assert(q);
	if (q->fear)
	{
		return q->fear->val;
	}
	else {
		return NULL;
	}

}
QNodeType QNodeFront(Queue* q)
{
	assert(q);
	if (q->front)
	{
		return q->front->val;
	}
	else {
		return NULL;
	}

}

bool QueueEmpty(Queue* q)
{
	/*if (size)
	{
		return true;
	else
		return false;*/
	/*return size == 0;*/
	return q->fear = NULL;

}